import request from './index'
// 是否全局消息提示
const requestOptions = {
  globalErrorMessage: true,
  globalSuccessMessage: true
}

// 获取角色列表
export function getRolesList(data?: any) {
  return request.get('roles', {
    requestOptions
  })
}

// 创建角色
export function createRole(data?: any) {
  return request.post('roles', data, {
    requestOptions
  })
}

// 通过角色id获取详情
export function getRoleById(data?: any) {
  return request.get(`roles${data.id}`, {
    requestOptions
  })
}

// 更新角色信息
export function updateRole(data?: any) {
  return request.put(
    `roles/${data.id}`,
    {
      roleName: data.roleName,
      roleDesc: data.roleDesc
    },
    {
      requestOptions
    }
  )
}

// 删除角色
export function deleteRole(data?: any) {
  return request.delete(`roles/${data.id}`, {
    requestOptions
  })
}

// 为角色授权
export function updateRoleRight(data?: any) {
  return request.post(
    `roles/${data.id}/rights`,
    {
      rids: data.rids
    },
    {
      requestOptions
    }
  )
}

// 删除角色权限
export function deleteRoleRight(data?: any) {
  return request.delete(`roles/${data.id}/rights/${data.rightId}`, {
    requestOptions
  })
}
